home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / bfd / i386aout.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  6KB  |  173 lines

  1. /* BFD back-end for i386 a.out binaries.
  2.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of BFD, the Binary File Descriptor library.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #define    PAGE_SIZE    4096
  21. #define    SEGMENT_SIZE    PAGE_SIZE
  22. #define TEXT_START_ADDR    0x8000 
  23. #define ARCH 32
  24. #define BYTES_IN_WORD 4
  25.  
  26. #include "bfd.h"
  27. #include "sysdep.h"
  28. #include "libbfd.h"
  29. #include "aout64.h"
  30. #include "stab.gnu.h"
  31. #include "ar.h"
  32. #include "libaout.h"           /* BFD a.out internal data structures */
  33.  
  34. bfd_target *aout386_callback ();
  35.  
  36. bfd_target *
  37. DEFUN(aout386_object_p,(abfd),
  38.      bfd *abfd)
  39. {
  40.   struct external_exec exec_bytes;
  41.   struct internal_exec exec;
  42.  
  43.   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
  44.       != EXEC_BYTES_SIZE) {
  45.     bfd_error = wrong_format;
  46.     return 0;
  47.   }
  48.  
  49.   exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
  50.  
  51.   if (N_BADMAG (exec)) return 0;
  52.  
  53.   NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
  54.   return aout_32_some_aout_object_p (abfd, &exec, aout386_callback);
  55. }
  56.  
  57. /* Finish up the reading of the file header */
  58. bfd_target *
  59. DEFUN(aout386_callback,(abfd),
  60.       bfd *abfd)
  61. {
  62.   struct internal_exec *execp = exec_hdr (abfd);
  63.   
  64.   WORK_OUT_FILE_POSITIONS(abfd, execp) ;
  65.   
  66.   /* Determine the architecture and machine type of the object file.  */
  67.   bfd_default_set_arch_mach(abfd, bfd_arch_i386, 0);
  68.   adata(abfd)->page_size = PAGE_SIZE;
  69. #ifdef SEGMENT_SIZE
  70.   adata(abfd)->segment_size = SEGMENT_SIZE;
  71. #else
  72.   adata(abfd)->segment_size = PAGE_SIZE;
  73. #endif
  74.   adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
  75.   return abfd->xvec;
  76. }
  77.  
  78. static boolean
  79. DEFUN(aout386_mkobject,(abfd),
  80.       bfd *abfd)
  81. {
  82.     if (aout_32_mkobject(abfd) == false)
  83.       return false;
  84.     adata(abfd)->page_size = PAGE_SIZE;
  85. #ifdef SEGMENT_SIZE
  86.   adata(abfd)->page_size = SEGMENT_SIZE;
  87. #else
  88.   adata(abfd)->segment_size = PAGE_SIZE;
  89. #endif
  90.     adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
  91.     return true;
  92. }
  93.  
  94. /* Write an object file.
  95.    Section contents have already been written.  We write the
  96.    file header, symbols, and relocation.  */
  97.  
  98. boolean
  99. DEFUN(aout386_write_object_contents,(abfd),
  100.       bfd *abfd)
  101. {
  102.   bfd_size_type data_pad = 0;
  103.   struct external_exec exec_bytes;
  104.   struct internal_exec *execp = exec_hdr (abfd);
  105.  
  106.   WRITE_HEADERS(abfd, execp);
  107.   return true;
  108. }
  109.  
  110. /* Transfer vector */
  111.  
  112. /* We use BSD archive files.  */
  113. #define    aout386_openr_next_archived_file    bfd_generic_openr_next_archived_file
  114. #define    aout386_generic_stat_arch_elt    bfd_generic_stat_arch_elt
  115. #define    aout386_slurp_armap        bfd_slurp_bsd_armap
  116. #define    aout386_slurp_extended_name_table    bfd_true
  117. #define    aout386_write_armap        bsd_write_armap
  118. #define    aout386_truncate_arname        bfd_bsd_truncate_arname
  119.  
  120. /* We don't support core files here.  */
  121. #define    aout386_core_file_failing_command _bfd_dummy_core_file_failing_command
  122. #define    aout386_core_file_failing_signal _bfd_dummy_core_file_failing_signal
  123. #define    aout386_core_file_matches_executable_p    \
  124.                 _bfd_dummy_core_file_matches_executable_p
  125. #define    aout386_core_file_p        _bfd_dummy_target
  126.  
  127. #define aout386_bfd_debug_info_start        bfd_void
  128. #define aout386_bfd_debug_info_end        bfd_void
  129. #define aout386_bfd_debug_info_accumulate    (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
  130.  
  131. #define aout386_close_and_cleanup    aout_32_close_and_cleanup
  132. #define aout386_set_section_contents    aout_32_set_section_contents
  133. #define aout386_get_section_contents    aout_32_get_section_contents
  134. #define aout386_new_section_hook    aout_32_new_section_hook
  135. #define aout386_get_symtab_upper_bound    aout_32_get_symtab_upper_bound
  136. #define aout386_get_symtab        aout_32_get_symtab
  137. #define aout386_get_reloc_upper_bound    aout_32_get_reloc_upper_bound
  138. #define aout386_canonicalize_reloc    aout_32_canonicalize_reloc
  139. #define aout386_make_empty_symbol    aout_32_make_empty_symbol
  140. #define aout386_print_symbol        aout_32_print_symbol
  141. #define aout386_get_lineno        aout_32_get_lineno
  142. #define aout386_set_arch_mach        aout_32_set_arch_mach
  143. #define aout386_find_nearest_line    aout_32_find_nearest_line
  144. #define aout386_sizeof_headers        aout_32_sizeof_headers
  145.  
  146. bfd_target i386aout_vec =     /* Intel 386 running a.out, embedded. */
  147. {
  148.   "a.out-i386",            /* name */
  149.   bfd_target_aout_flavour,
  150.   false,            /* target byte order */
  151.   false,            /* target headers byte order */
  152.   (HAS_RELOC | EXEC_P |        /* object flags */
  153.    HAS_LINENO | HAS_DEBUG |
  154.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  155.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  156.   ' ',                /* ar_pad_char */
  157.   16,                /* ar_max_namelen */
  158.   1,                /* minimum alignment */
  159.                  /* data swap routines */
  160.   _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16,
  161.                 /* header swap routines */
  162.   _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16,
  163.  
  164.   {_bfd_dummy_target, aout386_object_p, /* bfd_check_format */
  165.      bfd_generic_archive_p, aout386_core_file_p},
  166.   {bfd_false, aout386_mkobject,    /* bfd_set_format */
  167.      _bfd_generic_mkarchive, bfd_false},
  168.   {bfd_false, aout386_write_object_contents, /* bfd_write_contents */
  169.      _bfd_write_archive_contents, bfd_false},
  170.  
  171.   JUMP_TABLE(aout386)
  172. };
  173.